package com.mike.uaa.web;

/**
 * @author z zhang
 */
public abstract class ResponseBuilder {

    public static <T> ApiResponse<T> ok(T data) {
        return ResponseBuilder.ok(DataResponse.SUCCESS_MESSAGE(), data);
    }

    public static <T> ApiResponse<T> ok() {
        return new ApiResponse<>(DataResponse.SUCCESS_STATE(), DataResponse.SUCCESS_MESSAGE());
    }

    public static <T> ApiResponse<T> ok(String message, T data) {
        return new ApiResponse<>(DataResponse.SUCCESS_STATE(), message, data);
    }

    public static <T> ApiResponse<T> fail() {
        return new ApiResponse<>(DataResponse.FAILED_STATE(), DataResponse.FAILED_MESSAGE());
    }

    public static <T> ApiResponse<T> fail(String message) {
        return new ApiResponse<>(DataResponse.FAILED_STATE(), message);
    }

    public static <T> ApiResponse<T> of(Integer state, String message) {
        return new ApiResponse<>(state, message);
    }

    public static <T> ApiResponse<T> of(Integer state, String message, T data) {
        return new ApiResponse<>(state, message, data);
    }

    public static <T> ApiResponse<T> of(DataResponse DataResponse, String message) {
        return of(DataResponse.getStatus(), message);
    }

    public static <T> ApiResponse<T> of(DataResponse DataResponse) {
        return of(DataResponse.getStatus(), DataResponse.getMessage());
    }

    public static <T> ApiResponse<T> badRequest() {
        return ResponseBuilder.of(400, "参数错误，请检查输入。");
    }

    public static <T> ApiResponse<T> unauthorized() {
        return ResponseBuilder.of(401, "该功能需要登录后才能访问，请登录后再访问。");
    }

    public static <T> ApiResponse<T> forbidden() {
        return of(403, "您没有操作该功能的权限，请联系管理员授权后操作。");
    }

    public static <T> ApiResponse<T> internalServerError() {
        return of(500, "服务器开小差了！请稍后再试。");
    }

    //my
    public static <T> ApiResponse<T> authRequest() {
        return ResponseBuilder.of(20010, "用户不存,请重新输入。");
    }

    private ResponseBuilder() {

    }
}
